//
//  SHVisitorViewController.swift
//  三期微博1
//
//  Created by TownFish on 16/7/20.
//  Copyright © 2016年 TownFish. All rights reserved.
//

import UIKit

class SHVisitorViewController: UIViewController {

    //判断用户是否登录
    var isLogin: Bool = SHUserAccountViewModel.sharedTools.isLogin
    //访客视图
    var visitorView: SHVisitorView?
    
    
    
    //MARK: - 监听方法导航栏左右的登录和注册
    @objc private func loginClick() {
        print("登录或者注册按钮点击")
        let oauthVc = SHOAuthViewController()
        //模态登录控制器
        presentViewController(UINavigationController(rootViewController: oauthVc), animated: true, completion: nil)
        
    }
    
    
    override func loadView() {
        //判断是否为登录状态
        isLogin ? (view = tableView) : setupVisitorView()
    }
    
    
    
    override func viewDidLoad() {
        super.viewDidLoad()
    }
    
    //MARK: - 设置访客视图
    func setupVisitorView() {
        //设置为访客视图的UI界面
        visitorView = SHVisitorView()
        //设置闭包在点击登录的时候调用
        visitorView?.closure = {[weak self] in
            //调用上面的打印方法
            //            print("登录或者注册按钮点击")
            self?.loginClick()
        }
        view = visitorView
        setupNav()
    }
    
    //SHOAuthViewController
    // MARK: - 设置导航按钮
    func setupNav(){
        //        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "登录", style: UIBarButtonItemStyle.Plain, target: self, action: "loginClick")
        
        //使用遍历构造函数抽取创建按钮方法
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "登录", target: self, action: "loginClick")
        //使用重载方法抽取创建按钮方法
        navigationItem.rightBarButtonItem = SHBarButtonItem(title: "注册", target: self, action: "loginClick")
        
        
        
        //改用上面方法
//        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "注册", style: UIBarButtonItemStyle.Plain, target: self, action: "loginClick")
        
   
//        let button = UIButton()
//        button.addTarget(self, action: "loginClick", forControlEvents: UIControlEvents.TouchUpInside)
//        button.setTitle("登录", forState: UIControlState.Normal)
//        button.setTitleColor(UIColor.orangeColor(), forState: UIControlState.Normal)
//        button.titleLabel?.font = UIFont.systemFontOfSize(15)
//        button.sizeToFit()
//        navigationItem.leftBarButtonItem = UIBarButtonItem(customView: button)
    }
    
    
    
    //MARK : - 懒加载控件
    lazy var tableView: UITableView = UITableView()
}
